package cn.edu.service.impl;

import cn.edu.mapper.dep_ExamineMapper;
import cn.edu.pojo.All;
import cn.edu.pojo.PageBean;
import cn.edu.pojo.teacher;
import cn.edu.service.ExamineService;
import cn.edu.service.dep_ExamineService;
import cn.edu.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * @author Davey chan
 */
public  class dep_ExamineServiceImpl implements dep_ExamineService {
    SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();


    @Override
    public void agree(Integer id) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_ExamineMapper mapper = sqlSession.getMapper(dep_ExamineMapper.class);
//     调用方法
     mapper.agree(id);
        sqlSession.commit();
        sqlSession.close();

    }
    @Override
    public void disagree(Integer id) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_ExamineMapper mapper = sqlSession.getMapper(dep_ExamineMapper.class);
//     调用方法
        mapper.disagree(id);
        sqlSession.commit();
        sqlSession.close();

    }

    @Override
    public PageBean<All> selectByPage(int currentPage, int pageSize) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_ExamineMapper mapper = sqlSession.getMapper(dep_ExamineMapper.class);
//     计算开始的索引
        int begin=(currentPage-1)*pageSize;
//        计算查询的条目数
        int size =pageSize;
//        查询当前页的数据

        List<All> rows = mapper.selectBypage(begin, size);
//        查询总记录数
        int totalCount = mapper.selectTotalCount();
//封装pageBean

        PageBean<All> pageBean=new PageBean<>();
        pageBean.setRows(rows);
        pageBean.setTotalCount(totalCount);

        sqlSession.close();
        return pageBean;
    }
    @Override
    public PageBean<teacher> selectByPage2(int currentPage, int pageSize) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_ExamineMapper mapper = sqlSession.getMapper(dep_ExamineMapper.class);
//     计算开始的索引
        int begin=(currentPage-1)*pageSize;
//        计算查询的条目数
        int size =pageSize;
//        查询当前页的数据

        List<teacher> rows = mapper.selectBypage2(begin, size);
//        查询总记录数
        int totalCount = mapper.selectTotalCount2();
//封装pageBean

        PageBean<teacher> pageBean=new PageBean<>();
        pageBean.setRows(rows);
        pageBean.setTotalCount(totalCount);

        sqlSession.close();
        return pageBean;
    }

    @Override
    public void cancle(Integer id) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_ExamineMapper mapper = sqlSession.getMapper(dep_ExamineMapper.class);
//     调用方法
        mapper.cancle(id);
        sqlSession.commit();
        sqlSession.close();

    }
}
